<template>
    <div class="addressList">
        <div class="topBox">
            <img class="leftImg" src="../../static/imgs/left_b.png" @click="handleBack" alt="">
            <div class="title">
                {{ $t('assemble.地址列表') }}
            </div>
            <div class="add" @click="handleAddorEdit(0)">
                {{ $t('assemble.添加地址') }}
            </div>
        </div>


        <div class="dataList">
            <div class="listItem" v-for="(item, index) in dataList">
                <div class="company">
                    {{ item.company }}
                </div>
                <div class="nameAndphone">
                    <div>{{ item.name }}</div>
                    <div class="phone">{{ item.mobile }}</div>
                </div>
                <div class="address nameAndphone">
                    {{ item.site }}
                </div>
                <div class="code nameAndphone">
                    邮编：{{ item.postcode }}
                </div>
                <div class="heng"></div>


                <div class="bottonBox">

                    <div class="bottom_left">
                        <img v-if="item.default == 0" class="statusimg" src="../../static/imgs/null.png" alt="" srcset="">
                        <img v-else class="statusimg" src="../../static/imgs/fill.png" alt="" srcset="">
                        {{ $t('assemble.默认') }}
                    </div>

                    <div class="bottom_right">
                        <div @click="handleAddorEdit(1, item)">
                            {{ $t('assemble.编辑') }}
                        </div>
                        <div class="shu"></div>
                        <div @click="handleDelshow(item)">
                            {{ $t('assemble.删除') }}
                        </div>
                    </div>

                </div>

            </div>

        </div>

    </div>
</template>
<script>
import { Dialog, Toast } from 'vant';
import { getAdresslist, delAdress } from '../..//utils/api'
import debounce from '@/utils/debounce.js';
export default {
    components: {
        Dialog,

    },
    data() {
        return {
            content: "",
            lang: 'zh',
            dataList: [],

        }
    },
    created() {
        this.$i18n.locale = localStorage.getItem('langtype')
        this.lang = localStorage.getItem('langtype')

    },
    mounted() {
        this.getAdresslistdata()
    },
    methods: {
        async getAdresslistdata() {
            let res = await getAdresslist()
            if (res.code == 1) {
                this.dataList = res.data
            }
            // if (res.code == 401) {
            //     this.$router.push({ path: '/login' })
            // }
        },
        handleDelshow(item) {
            this.delId = item.id
            Dialog.confirm({
                title: this.$t('assemble.删除'),
                message: this.$t('assemble.确定删除删除这个地址吗'),
                confirmButtonText: this.$t('assemble.确定'),
                cancelButtonText: this.$t('assemble.取消'),
            }).then(async () => {
                let res = await delAdress(
                    { id: this.delId }
                )
                if (res.code == 1) {
                    Toast(this.$t('assemble.删除成功'));
                    this.getAdresslistdata()
                } else {
                    Toast(res.msg);
                }
            })
                .catch(() => { });
        },
        handleAddorEdit(type, item) {
            if (type == 1) {
                localStorage.setItem("addressData", JSON.stringify(item))
            }
            this.$router.push({ path: '/pages/mine/addoreditAddress', query: { type } })
        },

        handleBack() {
            this.$router.back(1)
        },
    },

}
</script>

<style scoped lang="scss">
@media screen and (max-width: 750px) {
    .topBox {
        width: 100%;
        height: 44px;
        // padding: 10px 15px;
        padding-top: 10px;
        position: relative;
        font-family: PingFang SC, PingFang SC;
        font-weight: 600;
        font-size: 16px;
        color: #333333;
        line-height: 19px;
        text-align: left;
        font-style: normal;
        text-transform: none;

        .leftImg {
            width: 24px;
            height: 24px;
            position: absolute;
            top: 10px;
            left: 15px;
        }

        .add {
            position: absolute;
            top: 10px;
            right: 20px;
            color: #E00000;
            font-size: 15px;
        }

        .title {
            width: 100%;
            text-align: center;

        }
    }

    .dataList {
        margin-top: 20px;

        .listItem {
            width: 90%;
            // height: 126px;
            border-radius: 10px 10px 10px 10px;
            border: 1px solid #EDEDED;
            margin: 0 auto;
            padding: 15px;
            box-sizing: border-box;
            // display: flex;
            // flex-direction: column;
            // justify-content: space-between;
            margin-bottom: 20px;

            .company {
                font-family: PingFang SC, PingFang SC;
                font-weight: 400;
                font-size: 14px;
                color: #333333;
                line-height: 16px;
                text-align: left;
                font-style: normal;
                text-transform: none;
            }

            .nameAndphone {
                font-family: PingFang SC, PingFang SC;
                font-weight: 400;
                font-size: 14px;
                color: #818181;
                line-height: 16px;
                text-align: left;
                font-style: normal;
                text-transform: none;
                display: flex;

                .phone {
                    margin-left: 10px;
                }
            }

            .heng {
                width: 100%;
                height: 1px;
                background-color: #EDEDED;
                margin: 10px auto;
            }

            .bottonBox {
                display: flex;
                justify-content: space-between;
                align-items: center;

                .bottom_left {
                    font-family: PingFang SC, PingFang SC;
                    font-weight: 400;
                    font-size: 12px;
                    color: #B1B1B1;
                    line-height: 14px;
                    text-align: left;
                    font-style: normal;
                    display: flex;
                    align-items: center;

                    .statusimg {
                        width: 16px;
                        height: 16px;
                    }
                }

                .bottom_right {
                    display: flex;
                    font-family: PingFang SC, PingFang SC;
                    font-weight: 400;
                    font-size: 12px;
                    color: #E00000;
                    line-height: 14px;
                    text-align: left;
                    font-style: normal;
                    text-transform: none;

                    .shu {
                        width: 1px;
                        height: 12px;
                        background-color: #B1B1B1;
                        margin: 0 20px;
                    }
                }
            }
        }
    }


}

@media screen and (min-width: 751px) and (max-width: 1300px) {
    .topBox {
        width: 100%;
        height: 88px;
        // padding: 10px 15px;
        padding-top: 20px;
        position: relative;
        font-family: PingFang SC, PingFang SC;
        font-weight: 600;
        font-size: 25px;
        color: #333333;
        line-height: 19px;
        text-align: left;
        font-style: normal;
        text-transform: none;
        display: flex;
        align-items: center;

        .leftImg {
            width: 48px;
            height: 48px;
            position: absolute;
            top: 40px;
            left: 30px;
        }

        .add {
            position: absolute;
            top: 40px;
            right: 30px;
            color: #E00000;
        }

        .title {
            width: 100%;
            text-align: center;

        }
    }

    .dataList {
        .listItem {
            width: 90%;
            // height: 126px;
            border-radius: 10px 10px 10px 10px;
            border: 1px solid #EDEDED;
            margin: 0 auto;
            padding: 30px;
            box-sizing: border-box;
            // display: flex;
            // flex-direction: column;
            // justify-content: space-between;
            margin-bottom: 20px;

            .company {
                font-family: PingFang SC, PingFang SC;
                font-weight: 400;
                font-size: 22px;
                color: #333333;
                line-height: 16px;
                text-align: left;
                font-style: normal;
                text-transform: none;
            }

            .nameAndphone {
                font-family: PingFang SC, PingFang SC;
                font-weight: 400;
                font-size: 18px;
                color: #818181;
                line-height: 16px;
                text-align: left;
                font-style: normal;
                text-transform: none;
                display: flex;
                margin: 10px 0;

                .phone {
                    margin-left: 10px;
                }
            }

            .heng {
                width: 100%;
                height: 1px;
                background-color: #EDEDED;
                margin: 20px auto;
            }

            .bottonBox {
                display: flex;
                justify-content: space-between;
                align-items: center;

                .bottom_left {
                    font-family: PingFang SC, PingFang SC;
                    font-weight: 400;
                    font-size: 20px;
                    color: #B1B1B1;
                    line-height: 14px;
                    text-align: left;
                    font-style: normal;
                    display: flex;
                    align-items: center;

                    .statusimg {
                        width: 30px;
                        height: 30px;
                    }
                }

                .bottom_right {
                    display: flex;
                    align-items: center;
                    font-family: PingFang SC, PingFang SC;
                    font-weight: 400;
                    font-size: 20px;
                    color: #E00000;
                    line-height: 14px;
                    text-align: left;
                    font-style: normal;
                    text-transform: none;

                    .shu {
                        width: 2px;
                        height: 24px;
                        background-color: #B1B1B1;
                        margin: 0 40px;
                    }
                }
            }
        }
    }
}
</style>